import React, { useEffect, useState } from 'react'
import { Table } from "antd";
import $http from "@/services";
import { typeRecord } from './TypeColumns';
export default function RecordTable({ interfaced, params, type }) {
    const [dataSourse, setDataSourse] = useState([]);
    const [loading, setLoading] = useState(false);
    const [total, setTotal] = useState(0)
    // 初始化请求
    useEffect(() => {
        // 当interfaced请求过来时进行
        interfaced && _initRecordDatas();
    }, [interfaced])

    // 初始化
    async function _initRecordDatas() {
        setLoading(true);
        const data = await $http[interfaced](params);
        console.log(data)
        setLoading(false);
        setDataSourse(data.data.list);
        setTotal(data.data.total);
    }


    return (
        <Table
            dataSource={dataSourse}
            loading={loading}
            rowKey={(el) => el._id}
            columns={typeRecord[type]}
            pagination={{ defaultPageSize: 5, total }}
        >

        </Table>
    )
}
